package logic

import (
	"baidu-dev/models"
	"context"
	"errors"

	"baidu-dev/baidurpc/baidurpc"
	"baidu-dev/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentAddLogic {
	return &CommentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论发布
func (l *CommentAddLogic) CommentAdd(in *baidurpc.CommentAddRequest) (*baidurpc.CommentAddResponse, error) {
	// todo: add your logic here and delete this line

	if in.Content == "" {
		return nil, errors.New("请输入评论内容")
	}

	if in.Content == "垃圾" || in.Content == "骗人" {
		return nil, errors.New("含违规词汇，请修改")
	}

	comment := &models.Comment{
		VideoId: int(in.VideoId),
		UserId:  int(in.UserId),
		Content: in.Content,
	}
	if err := comment.CommentAdd(models.DB); err != nil {
		return nil, err
	}

	return &baidurpc.CommentAddResponse{
		Comment: int64(comment.ID),
	}, nil
}
